package com.ruoyi.system.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.Shopping;
import com.ruoyi.system.mapper.ShoppingMapper;
import com.ruoyi.system.service.IShoppingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 购物车Service业务层处理
 * 
 * @author ...
 * @date 2022-03-18
 */
@Service
public class ShoppingServiceImpl implements IShoppingService 
{
    @Autowired
    private ShoppingMapper shoppingMapper;

    /**
     * 查询购物车
     * 
     * @param id 购物车主键
     * @return 购物车
     */
    @Override
    public Shopping selectShoppingById(Integer id)
    {
        return shoppingMapper.selectShoppingById(id);
    }

    /**
     * 查询购物车列表
     * 
     * @param shopping 购物车
     * @return 购物车
     */
    @Override
    public List<Shopping> selectShoppingList(Shopping shopping)
    {
        return shoppingMapper.selectShoppingList(shopping);
    }

    /**
     * 新增购物车
     * 
     * @param shopping 购物车
     * @return 结果
     */
    @Override
    public int insertShopping(Shopping shopping)
    {
        shopping.setCreateTime(DateUtils.getNowDate());
        return shoppingMapper.insertShopping(shopping);
    }

    /**
     * 修改购物车
     * 
     * @param shopping 购物车
     * @return 结果
     */
    @Override
    public int updateShopping(Shopping shopping)
    {
        shopping.setUpdateTime(DateUtils.getNowDate());
        return shoppingMapper.updateShopping(shopping);
    }

    /**
     * 批量删除购物车
     * 
     * @param ids 需要删除的购物车主键
     * @return 结果
     */
    @Override
    public int deleteShoppingByIds(Integer[] ids)
    {
        return shoppingMapper.deleteShoppingByIds(ids);
    }

    /**
     * 删除购物车信息
     *
     * @param id 购物车主键
     * @return 结果
     */
    @Override
    public int deleteShoppingById(Integer id) {
        return shoppingMapper.deleteShoppingById(id);
    }

    @Override
    public List<Shopping> getMyShop() {
        int userId = SecurityUtils.getUserId().intValue();
        return shoppingMapper.getMyShop(userId);
    }
}
